package com.dubbo.lian.cms.modules.app.service.impl;
 import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dubbo.lian.cms.modules.app.SysMission;
import com.dubbo.lian.cms.modules.app.mapper.SysMissionMapper;
import com.dubbo.lian.cms.modules.app.service.ISysMissionService;
import com.dubbo.lian.cms.modules.app.service.ISysPlanService;
import com.dubbo.lian.common.util.BaseR;
import com.dubbo.lian.common.util.ReturnTemplateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 import java.util.HashMap;
import java.util.List;
import java.util.Map;
 /**
 * <p>
 * 系统设置的任务列表  服务实现类
 * </p>
 *
 * @author lian
 * @since 2016-12-22
 */
@Service
public class SysMissionServiceImpl extends ServiceImpl<SysMissionMapper, SysMission> implements ISysMissionService {
     private static Logger logger = LoggerFactory.getLogger(SysMissionServiceImpl.class);
    @Autowired
    private ISysPlanService sysPlanService;
    @Autowired
    private SysMissionMapper sysMissionMapper;
     @Override
    public BaseR selectListGetCanAddMission(JSONObject obj) {
        int planStage = obj.getIntValue("planStage");
        int sysPlanId = obj.getIntValue("sysPlanId");
        Integer pageSize = obj.getInteger("pageSize");
        Integer pageNum = obj.getInteger("pageNum");
         if(pageSize==null){
            pageSize = 20;
        }
        if(pageNum==null){
            pageNum = 1;
        }
         EntityWrapper ew = new EntityWrapper();
        ew.where("sys_plan_id={0}",sysPlanId);
        ew.and("plan_stage={0}",planStage);
        Page page = new Page(pageNum,pageSize);
        List<SysMission> missions=super.selectPage(page,ew).getRecords();
        Map missionListMap = new HashMap();
        missionListMap.put("missionList",missions);
        return ReturnTemplateUtil.returnOfMap(missionListMap);
    }
     @Override
    public BaseR selectSysMissionStageCoin(JSONObject json) {
        List<Map> list;
        try {
            int sysPlanId = json.getInteger("sysPlanId");
            Map selectMap= new HashMap<>();
            selectMap.put("sysPlanId",sysPlanId);
            list = sysMissionMapper.selectSysMissionStageCoin(selectMap);
        } catch (Exception e) {
            return ReturnTemplateUtil.errReturn(e.getMessage(),logger);
        }
        return ReturnTemplateUtil.returnOfObject(list);
    }
 }